#!/usr/bin/python
# GM_physicalparameters.py
'''Lists physical parameters used by modules of the GalacticModel program.'''

# Parameters directly stated in Han 2008
# Distance from sun to galactic center, in kpc
R0 = 8
# Disc scale length, R dirn, in kpc
hR = 3.5
# Dust scale height, z dirn, in pc.  Note that Cox quotes instead the "Sandage cosec law" with a scale height of 100 pc rather than the 150 pc Han quotes.
hdz = 150
# Disc scale heights corresponding to the magnitudes in MvList below, z dirn, in pc
ScaleList = [90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 200, 325, 455, 585, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600]
# Bulk velocities of the MW rotation, in d, l, b dirns, in km/s
bulk_vels = (0, 220, 0)
#bulk_vels = (0, 0, 0)
# Velocity dispersions of the MW stars, in d, l, b dirns, in km/s
sigma_vels = (38, 25, 20)



# The luminosity function in the solar neighborhood from Binney & Merrifield 1998
# Units of LumFuncList are stars per pc cubed per magnitude
MvList = [-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19]
LumFuncList = [1e-8, 6e-8, 2.9e-7, 1.3e-6, 5e-6, 2.5e-5, 1e-4, 3e-4, 5e-4, 1.2e-3, 1.7e-3, 2.9e-3, 3e-3, 2.9e-3, 3.3e-3, 4.2e-3, 7e-3, 9e-3, 1.27e-2, 1.02e-2, 1.02e-2, 1.27e-2, 1.02e-2, 5.1e-3, 2.2e-3, 1.3e-3]


# Bochanski et al. 2010

#Need provisions for extinction#
# After a long and painful time spent figuring out the references in Bochanski et al. regarding extinction, I think I've figured out what's going on.  Bochanski used three components to construct an extinction law:
#1) Dust (infrared emission) maps from Schlegel et al. to determine where, in two dimensions, the dust is.  A handwavy reference to Marshall et al. (the specific relevance of this reference to this paper on 3d dust maps was hard to determine) seems to suggest that they assume ALL the dust in the 2d maps is between the observer and the stars.
#2) An unnamed constant connects dust quantity to absolute extinction in one band (V?).
#3) The extinction law from Cardelli et al. is used to determine the relationship between different bands.  The law in question from this paper is "universal up to a constant" where the constant seems to represent typical dust grain size along a given line of sight; the typical galactic value of 3.1 is used.
# None of this tells me the absolute extinction value, nor can it be directly derived from the information provided.  So, fuck it - I'm going to try a value of 0.7 mag per kpc of extinction in r band.  The goddam "rule of thumb".  If that doesn't work out, I'll try something else, like fitting for the value, or something.  To that end, 

# Values describing Bochanski's derived galactic model.  Should be good near zenith, dodgy-esque elsewhere, as spheroid is important at zenith for apparent magnitudes below 18 in full 3d fits.  This model is fit to data only near zenith and probably good for that region.
# Not sure why I have uncertainties, but there they are.
BoCorrectedValues = {'BoZ0thin' : 300.,
                     'BoR0thin' : 3100.,
                     'BoZ0thick' : 2100.,
                     'BoR0thick' : 3700.,
                     'Bof' : 0.96,
                     'BoZ0thin_error' : 15.,
                     'BoR0thin_error' : 100.,
                     'BoZ0thick_error' : 700.,
                     'BoR0thick_error' : 800.,
                     'Bof_error' : 0.02,
                     }
# Not sure there's any reason to have this... but hey, if I ever need it, it's already here.
BoUncorrectedValues = {'BoZ0thin' : 255.,
                       'BoR0thin' : 2200.,
                       'BoZ0thick' : 1360.,
                       'BoR0thick' : 4100.,
                       'Bof' : 0.97,
                       'BoZ0thin_error' : 12.,
                       'BoR0thin_error' : 65.,
                       'BoZ0thick_error' : 300.,
                       'BoR0thick_error' : 740.,
                       'Bof_error' : 0.006,
                       }
# System and single star LFs in r and J band
# Columns are absolute magnitude, mean (best) density value [in stars pc^-3 0.5 mag^-1 x 10^-3, which means (I think) that you multiply by 2000 to get the "real" value], max value, and min value
# For computation purposes these columns will become rows.  They were easier to enter this way.
BoSystemLF_rband = [[7.25,  1.87,  2.52,  1.45],
                    [7.75,  1.30,  1.68,  0.92],
                    [8.25,  1.35,  1.75,  0.99],
                    [8.75,  1.49,  1.87,  1.16],
                    [9.25,  1.83,  2.21,  1.52],
                    [9.75,  2.55,  2.99,  2.20],
                    [10.25, 3.68,  4.28,  3.24],
                    [10.75, 4.71,  5.50,  4.09],
                    [11.25, 5.36,  6.38,  4.57],
                    [11.75, 5.29,  6.44,  4.44],
                    [12.25, 4.58,  5.55,  3.89],
                    [12.75, 3.57,  4.29,  3.02],
                    [13.25, 2.84,  3.31,  2.47],
                    [13.75, 2.34,  2.70,  2.04],
                    [14.25, 3.09,  3.37,  2.66],
                    [14.75, 0.55,  1.21,  0.21],
                    [15.25, 2.60,  2.96,  2.24],
                    [15.75, 1.43,  1.71,  1.20]]
BoSingleLF_rband = [[7.25,  1.85,  2.51,  1.43],
                    [7.75,  1.31,  1.71,  0.93],
                    [8.25,  1.36,  1.77,  1.00],
                    [8.75,  1.49,  1.89,  1.15],
                    [9.25,  1.81,  2.21,  1.49],
                    [9.75,  2.53,  3.00,  2.17],
                    [10.25, 3.79,  4.46,  3.32],
                    [10.75, 5.16,  6.06,  4.51],
                    [11.25, 6.38,  7.50,  5.55],
                    [11.75, 6.86,  8.10,  5.97],
                    [12.25, 6.43,  7.47,  5.66],
                    [12.75, 5.33,  6.16,  4.62],
                    [13.25, 4.39,  5.04,  3.86],
                    [13.75, 3.84,  4.45,  3.33],
                    [14.25, 5.44,  6.26,  4.78],
                    [14.75, 0.92,  2.06,  0.32],
                    [15.25, 5.78,  6.89,  4.75],
                    [15.75, 4.75,  5.83,  4.06]]
BoSystemLF_Jband = [[5.25,  1.69,  2.24,  1.27],
                    [5.75,  1.73,  2.24,  1.25],
                    [6.25,  2.31,  2.91,  1.79],
                    [6.75,  3.72,  4.41,  3.16],
                    [7.25,  6.30,  7.35,  5.53],
                    [7.75,  8.10,  9.60,  6.93],
                    [8.25,  7.71,  9.37,  6.50],
                    [8.75,  5.82,  6.99,  4.92],
                    [9.25,  4.48,  5.19,  3.90],
                    [9.75,  4.04,  5.03,  3.22]]
BoSingleLF_Jband = [[5.25,  1.68,  2.25,  1.26],
                    [5.75,  1.75,  2.28,  1.27],
                    [6.25,  2.31,  2.93,  1.79],
                    [6.75,  3.69,  4.41,  3.12],
                    [7.25,  6.60,  7.77,  5.78],
                    [7.75,  9.50,  11.17, 8.27],
                    [8.25,  10.26, 12.04, 8.96],
                    [8.75,  8.60,  9.95,  7.48],
                    [9.25,  7.14,  8.23,  6.22],
                    [9.75,  7.08,  9.16,  5.73]]
# System and single star MFs
# Columns are log(M/Msun), mean (best) density value [in stars pc^-3 0.1 log M ^-1 x 10^-3 (spaces here representing ambiguity in the original paper's syntax; they weren't hot for parentheses), which means (I think) that you multiply by 1000, then divide by M(10^0.05 - 10^-0.05) = M*0.2307 to get the "real" linear value][see confused notes, pgs. 63 - 64, 6/28/11], max value, and min value
# For computation purposes these columns will become rows.  They were easier to enter this way.
BoSystemMF = [[-0.15,  2.53,  3.26,  1.79],
              [-0.25,  2.96,  3.69,  2.24],
              [-0.35,  4.59,  5.32,  3.85],
              [-0.45,  7.22,  8.28,  6.15],
              [-0.55,  8.27,  9.70,  6.84],
              [-0.65,  7.21,  8.53,  5.89],
              [-0.75,  5.38,  6.29,  4.47],
              [-0.85,  4.79,  5.45,  4.14],
              [-0.95,  5.11,  6.42,  3.41]]
BoSingleMF = [[-0.15,  2.56,  3.31,  1.80],
              [-0.25,  2.97,  3.71,  2.23],
              [-0.35,  4.55,  5.31,  3.79],
              [-0.45,  7.76,  8.93,  6.59],
              [-0.55,  10.04, 11.58, 8.50],
              [-0.65,  9.93,  11.36, 8.50],
              [-0.75,  8.12,  9.27,  6.97],
              [-0.85,  7.93,  9.08,  6.78],
              [-0.95,  10.92, 13.95, 7.11]]


# Data about observed star counts from Cox 1999.  Values for both V and I bands are provided.
# Galactic latitudes for which data is available
bvals = [0, 5, 10, 20, 30, 60, 90]
# Magnitudes for which data is available
MvVals = [12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]
# List of [lower bound, upper bound] pairs derived from MvVals
#limitset = [[11.5, 12.5],[12.5, 13.5],[13.5, 14.5],[14.5, 15.5],[15.5, 16.5],[16.5, 17.5],[17.5, 18.5],[18.5, 19.5],[19.5, 20.5],[20.5, 21.5],[21.5, 22.5],[22.5, 23.5],[23.5, 24.5],[24.5, 25.5]]

# Data, log10(stars deg**-2), in V band. Outer index is magnitude, inner index is latitude.
N_bM_V = [[1.751, 1.752, 1.743, 1.665, 1.544, 1.234, 1.160],
          [2.275, 2.267, 2.218, 2.085, 1.935, 1.603, 1.524],
          [2.708, 2.694, 2.618, 2.450, 2.279, 1.925, 1.838],
          [3.105, 3.085, 2.985, 2.781, 2.591, 2.209, 2.110],
          [3.485, 3.460, 3.331, 3.089, 2.875, 2.458, 2.347],
          [3.842, 3.809, 3.648, 3.363, 3.124, 2.673, 2.553],
          [4.170, 4.130, 3.939, 3.612, 3.349, 2.869, 2.744],
          [4.474, 4.428, 4.210, 3.845, 3.559, 3.052, 2.924],
          [4.776, 4.722, 4.468, 4.057, 3.748, 3.226, 3.092],
          [5.078, 5.011, 4.705, 4.236, 3.909, 3.389, 3.245],
          [5.342, 5.262, 4.903, 4.382, 4.046, 3.538, 3.382],
          [5.536, 5.448, 5.059, 4.510, 4.168, 3.665, 3.500],
          [5.684, 5.594, 5.195, 4.633, 4.286, 3.772, 3.604],
          [5.813, 5.722, 5.319, 4.749, 4.393, 3.863, 3.695]]
# Allsky average for same magnitudes (12 through 25), in V band
allsky_V = [1.556, 1.994, 2.372, 2.719, 3.047, 3.350, 3.632, 3.897, 4.156, 4.406, 4.626, 4.797, 4.937, 5.061]


# Data, log10(stars deg**-2), in I band. Outer index is magnitude, inner index is latitude.
N_bM_I = [[2.466, 2.434, 2.279, 2.011, 1.799, 1.450, 1.374],
          [2.922, 2.877, 2.671, 2.355, 2.138, 1.816, 1.728],
          [3.316, 3.262, 3.023, 2.678, 2.461, 2.149, 2.045],
          [3.650, 3.594, 3.344, 2.991, 2.772, 2.445, 2.326],
          [3.951, 3.897, 3.653, 3.301, 3.069, 2.702, 2.575],
          [4.243, 4.191, 3.955, 3.594, 3.341, 2.926, 2.799],
          [4.548, 4.494, 4.247, 3.861, 3.584, 3.133, 3.005],
          [4.868, 4.807, 4.530, 4.103, 3.804, 3.327, 3.191],
          [5.191, 5.120, 4.802, 4.326, 4.005, 3.503, 3.353],
          [5.479, 5.398, 5.039, 4.515, 4.173, 3.649, 3.488],
          [5.710, 5.623, 5.234, 4.673, 4.313, 3.770, 3.604],
          [5.909, 5.816, 5.400, 4.806, 4.430, 3.874, 3.706],
          [6.092, 5.991, 5.546, 4.916, 4.528, 3.970, 3.797],
          [6.258, 6.150, 5.669, 5.002, 4.606, 4.055, 3.875]]
# Allsky average for same magnitudes (12 through 25), in I band
allsky_I = [2.001, 2.396, 2.753, 3.075, 3.376, 3.663, 3.947, 4.230, 4.510, 4.761, 4.967, 5.145, 5.308, 5.453]



# Parameters for the distribution of lensing matter.  This is represented as a three part broken power law.
# Limits of each segment in solar masses, format [lower, upper].  The last upper limit does not appear in Kroupa et al., so I supplied a practical upper limit, representing roughly the maximum size for a solar-metallicity star.  The first lower limit appears as 0.08 in the paper; I stretched it to 0.069 here to cover the entire Mv-Mass relation tabulated.
masslimits = [[0.069, 0.5],
              [0.5, 1.0],
              [1.0, 100]]
# Power law indices
massindices = [-1.3, -2.2, -2.7]
# And multiplicative constants out in front
massmults = [0.035, 0.019, 0.019]

# Mass-Mv relation tabulated in Kroupa et al.
# [Mv, Mass] listed from dim/small to bright/big
MvMass = [[18.00, 0.0700],
          [16.96, 0.0854],
          [16.13, 0.101],
          [15.45, 0.116],
          [14.87, 0.132],
          [14.36, 0.147],
          [13.93, 0.163],
          [13.54, 0.178],
          [13.21, 0.193],
          [12.92, 0.209],
          [12.67, 0.224],
          [12.47, 0.240],
          [12.29, 0.255],
          [12.13, 0.271],
          [11.99, 0.286],
          [11.86, 0.301],
          [11.73, 0.317],
          [11.60, 0.332],
          [11.47, 0.348],
          [11.34, 0.363],
          [11.21, 0.379],
          [11.08, 0.394],
          [10.93, 0.409],
          [10.79, 0.425],
          [10.64, 0.440],
          [10.48, 0.456],
          [10.31, 0.471],
          [10.14, 0.487],
          [9.96, 0.502],
          [9.78, 0.517],
          [9.59, 0.533],
          [9.39, 0.548],
          [9.19, 0.564],
          [8.99, 0.579],
          [8.77, 0.595],
          [8.56, 0.610],
          [8.35, 0.626],
          [8.14, 0.641],
          [7.92, 0.656],
          [7.71, 0.672],
          [7.51, 0.687],
          [7.31, 0.703],
          [7.11, 0.718],
          [6.93, 0.734],
          [6.75, 0.749],
          [6.59, 0.764],
          [6.43, 0.780],
          [6.28, 0.795],
          [6.14, 0.811],
          [6.01, 0.826],
          [5.88, 0.842],
          [5.75, 0.857],
          [5.63, 0.872],
          [5.52, 0.888],
          [5.40, 0.903],
          [5.29, 0.919],
          [5.19, 0.934],
          [5.08, 0.950],
          [4.98, 0.965],
          [4.88, 0.980],
          [4.78, 0.996],
          [4.68, 1.011],
          [4.58, 1.027],
          [4.49, 1.042],
          [4.41, 1.058],
          [4.32, 1.073],
          [4.24, 1.088],
          [4.17, 1.104],
          [4.09, 1.119],
          [4.02, 1.135],
          [3.95, 1.150],
          [3.88, 1.166],
          [3.82, 1.181],
          [3.75, 1.196],
          [3.69, 1.212],
          [3.63, 1.227],
          [3.57, 1.243],
          [3.51, 1.258],
          [3.46, 1.274],
          [3.40, 1.289],
          [3.35, 1.304],
          [3.30, 1.320],
          [3.25, 1.335],
          [3.20, 1.351],
          [3.15, 1.366],
          [3.10, 1.382],
          [3.05, 1.397],
          [3.01, 1.412],
          [2.96, 1.428],
          [2.92, 1.443],
          [2.87, 1.459],
          [2.83, 1.474],
          [2.79, 1.490],
          [2.75, 1.505],
          [2.71, 1.521],
          [2.67, 1.536],
          [2.63, 1.551],
          [2.59, 1.567],
          [2.56, 1.582],
          [2.52, 1.598],
          [2.00, 1.862],
          [-3.00, 12.020]]


#[distance from galactic center, rotation velocity] in [kpc, km/s] as extracted from Sofue, Honma & Omodaka 2008
SofueRotV = [[0, 213.73239436619718],
             [0.022099447513812365, 218.30985915492954],
             #[0.02209944751381215, 222.18309859154928],
             #[0.02209944751381156, 225.35211267605632],
             #[0.02209944751381246, 229.22535211267603],
             #[0.022099447513810794, 232.3943661971831],
             #[0.022099447513811103, 235.9154929577465],
             [0.04419889502762418, 239.43661971830986],
             [0.06629834254143516, 242.95774647887322],
             #[0.06629834254143604, 246.4788732394366],
             [0.08839779005524746, 249.64788732394362],
             [0.11049723756905981, 252.46478873239437],
             [0.1767955801104973, 253.52112676056336],
             [0.2651933701657449, 252.11267605633802],
             [0.3314917127071824, 249.64788732394365],
             [0.37569060773480534, 246.83098591549296],
             [0.4419889502762431, 244.3661971830986],
             [0.48618784530386666, 241.54929577464787],
             [0.5524861878453032, 238.3802816901408],
             [0.61878453038674, 235.56338028169014],
             [0.6850828729281758, 232.04225352112675],
             [0.7734806629834245, 228.87323943661974],
             [0.8397790055248622, 225.70422535211267],
             [0.9502762430939212, 223.2394366197183],
             [1.0165745856353587, 220.4225352112676],
             [1.1491712707182322, 216.90140845070422],
             [1.303867403314917, 213.73239436619718],
             [1.4364640883977897, 210.56338028169012],
             [1.635359116022099, 208.09859154929575],
             [1.7900552486187842, 205.2816901408451],
             [1.9447513812154689, 202.11267605633802],
             [2.121546961325966, 198.94366197183098],
             [2.276243093922652, 196.1267605633803],
             [2.4309392265193366, 193.30985915492957],
             [2.6077348066298334, 190.8450704225352],
             [2.806629834254143, 189.7887323943662],
             [3.027624309392265, 191.54929577464787],
             [3.2265193370165743, 194.01408450704224],
             [3.3812154696132604, 196.83098591549293],
             [3.535911602209944, 199.64788732394365],
             [3.6906077348066297, 201.76056338028167],
             [3.845303867403315, 203.16901408450704],
             [4.044198895027624, 204.57746478873239],
             [4.220994475138121, 204.92957746478874],
             [4.486187845303866, 205.6338028169014],
             [4.707182320441988, 205.6338028169014],
             [4.950276243093922, 205.98591549295776],
             [5.171270718232043, 206.33802816901408],
             [5.392265193370165, 207.04225352112675],
             [5.635359116022099, 207.74647887323943],
             [5.878453038674033, 208.09859154929575],
             [6.121546961325967, 208.80281690140845],
             [6.3646408839779, 209.15492957746477],
             [6.585635359116022, 209.50704225352112],
             [6.87292817679558, 209.1549295774648],
             [7.160220994475138, 208.4507042253521],
             [7.403314917127071, 207.04225352112678],
             [7.580110497237569, 205.63380281690144],
             [7.756906077348066, 204.22535211267603],
             [7.955801104972375, 202.11267605633805],
             [8.132596685082873, 200],
             [8.30939226519337, 197.88732394366198],
             [8.530386740331492, 195.42253521126761],
             [8.751381215469612, 193.66197183098592],
             [8.950276243093922, 192.25352112676057],
             [9.171270718232044, 191.90140845070422],
             [9.414364640883978, 191.90140845070425],
             [9.657458563535911, 192.95774647887322],
             [9.878453038674033, 194.36619718309862],
             [10.099447513812153, 196.47887323943667],
             [10.342541436464089, 198.2394366197183],
             [10.585635359116022, 200],
             [10.850828729281767, 201.76056338028167],
             [11.07182320441989, 202.46478873239434],
             [11.314917127071823, 203.16901408450704],
             [11.580110497237568, 203.16901408450707],
             [11.823204419889505, 202.8169014084507],
             [12.066298342541437, 202.46478873239437],
             [12.30939226519337, 202.11267605633802],
             [12.53038674033149, 201.05633802816897],
             [12.751381215469612, 200.70422535211267],
             [13.01657458563536, 200],
             [13.303867403314916, 199.2957746478873],
             [13.546961325966853, 198.59154929577463],
             [13.834254143646408, 198.23943661971828],
             [14.121546961325967, 197.5352112676056],
             [14.386740331491715, 196.83098591549293],
             [14.651933701657457, 196.83098591549293],
             [14.917127071823206, 196.4788732394366],
             [15.204419889502763, 196.12676056338023],
             [15.469613259668508, 195.42253521126756],
             [15.756906077348066, 195.07042253521126],
             [16, 194.71830985915494],
             [16.30939226519337, 194.36619718309856],
             [16.574585635359114, 193.66197183098586],
             [16.861878453038674, 193.30985915492957],
             [17.14917127071823, 192.95774647887322],
             [17.4585635359116, 192.6056338028169],
             [17.701657458563535, 192.6056338028169],
             [17.944751381215468, 192.25352112676057],
             [18.1878453038674, 191.9014084507042],
             [18.430939226519335, 191.90140845070422],
             [18.696132596685082, 191.54929577464785],
             [18.939226519337016, 191.5492957746479],
             [19.20441988950276, 191.54929577464787],
             [19.447513812154696, 191.9014084507042],
             [19.646408839779006, 191.90140845070422],
             [19.80110497237569, 191.90140845070422]]
